<?php


namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Services\Admin\CategoryService;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
    private $categoryService;

    public function __construct(Request $request, CategoryService $categoryService){
        $this->request = $request;
        $this->categoryService = $categoryService;
    }

    public function getCategoryInfo(Request $request){
        $params = $request->input();
        $result = $this->categoryService->getCategoryInfo($params);
        return $result;
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function createOrUpdateBanner(Request $request){
        $this->validate($request, [
            'title' => 'required',
        ]);
        $result = $this->bannerService->createOrUpdateBanner($request->post());
        return $result;
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function deleteRole(Request $request){
        $result = $this->bannerService->deleteBanner($request->post('id'));
        return $result;
    }
}
